const shopMod = require('../model/shopMod.js')
// 该层处理数据库参数
const shopServ = {
  orderlistServ:async (data) => {
    const res = await shopMod.orderlistMod(data)
    // 获取已买id 以及 商品数量
    let gids = res.map((item) => {
      return item.gIDs
    })
    let nums = res.map((item) => {
      return item.good_nums.split(',')
    })
    // 使用上面的条件嵌套查询
   const  goodsRes =  await shopMod.relevetGoodsMod(gids)

    // 将其挂到res 结构上
    for(let i = 0 ; i < goodsRes.length ; i++){
      for(let j = 0 ; j < goodsRes[i].length ; j++){
        goodsRes[i][j].nums = nums[i][j]
      }
    }
   for(let i = 0 ; i < res.length ; i++){
    res[i].goodsInfo = goodsRes[i]
  }
    return res
  },

  orderlistWebServ:async (data) => {
    const res = await shopMod.orderlistWebMod(data)
    // 获取已买id 以及 商品数量
    let gids = res.list.map((item) => {
      return item.gIDs
    })
    let nums = res.list.map((item) => {
      return item.good_nums.split(',')
    })
    // 使用上面的条件嵌套查询
   const  goodsRes =  await shopMod.relevetGoodsMod(gids)

    for(let i = 0 ; i < goodsRes.length ; i++){
      for(let j = 0 ; j < goodsRes[i].length ; j++){
        goodsRes[i][j].nums = nums[i][j]
      }
    }
    // 将其挂到res 结构上
   for(let i = 0 ; i < res.list.length ; i++){
    res.list[i].goodsInfo = goodsRes[i]
  }
    return res
  },
  goodsUNIlistServ:async () => {
    const res = await shopMod.goodsUNIlistServ()
    return res
  },
  goodslistServ:async (data) => {
    const res = await shopMod.goodslistMod(data)
    return res
  },
  deliverInfoServ:async (data) => {
    await shopMod.deliverInfoMod(data)
  },
  deleteorderServ:async (data) => {
    await shopMod.deleteorderMod(data)
  },
  editOrderStatusServ:async (data) => {
    await shopMod.editOrderStatusWebMod(data)
  },
  deleteGoodWebServ:async (data) => {
    await shopMod.deleteGoodWebMod(data)
  },
  editGoodWebServ:async (data) => {
    await shopMod.editGoodWebMod(data)
  },
  addGoodWebServ:async (data) => {
    await shopMod.addGoodWebMod(data)
  }
}

module.exports = shopServ